package top.songxs.gmall.web.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import top.songxs.gmall.common.result.Result;
import top.songxs.gmall.feign.search.GoodsFeignClient;
import top.songxs.gmall.search.dto.SearchParamDTO;
import top.songxs.gmall.search.vo.SearchResponseVo;

@Controller
@Slf4j
public class SearchController {

    @Autowired
    private GoodsFeignClient goodsFeignClient;

    @GetMapping(value = "/list.html")
    public String searchListPage(SearchParamDTO searchParamDTO , Model model) {
        Result<SearchResponseVo> result = goodsFeignClient.search(searchParamDTO);

        SearchResponseVo searchResponseVo = result.getData() ;

        model.addAttribute("searchParam" , searchResponseVo.getSearchParam()) ;
        model.addAttribute("trademarkParam" , searchResponseVo.getTrademarkParam()) ;
        model.addAttribute("urlParam" , searchResponseVo.getUrlParam()) ;
        model.addAttribute("propsParamList" , searchResponseVo.getPropsParamList()) ;
        model.addAttribute("trademarkList" , searchResponseVo.getTrademarkList()) ;
        model.addAttribute("attrsList" , searchResponseVo.getAttrsList()) ;
        model.addAttribute("orderMap" , searchResponseVo.getOrderMap()) ;
        model.addAttribute("goodsList" , searchResponseVo.getGoodsList()) ;
        model.addAttribute("pageNo" , searchResponseVo.getPageNo()) ;
        model.addAttribute("totalPages" , searchResponseVo.getTotalPages()) ;
        System.out.println("跳转到搜索列表页面");
        return "list/index" ;
    }
}
